using System;
using System.Collections.Generic;

namespace SG.Lang.Dry.Mirrors
{
    public delegate bool NextNodeFetcher(ref Guid next, out ItemList node);

    [Serializable]
    public struct ItemList
    {
        private readonly Guid _item;

        private readonly Guid _next;

        public ItemList(ref Guid item)
        {
            _item = item;
            _next = Guid.Empty;
        }

        public ItemList(ref Guid item, ref Guid next)
        {
            _item = item;
            _next = next;
        }

        public IEnumerable<Guid> Nodes(NextNodeFetcher fetcher)
        {
            var current = this;
            Guid next;
            do
            {
                yield return current._item;
                next = current._next;
            } while (fetcher(ref next, out current));
        }
    }
}